# coding:utf-8
import gtk
import pynotify
import time

from const import *

class Notify(pynotify.Notification):
    def __init__(self):
        super(Notify, self).__init__('Rauth')
	self.set_urgency(pynotify.URGENCY_NORMAL)
        self.set_timeout(3000)
		
class Icon(gtk.StatusIcon):
	def __init__(self):
		gtk.StatusIcon.__init__(self)
		self.set_from_file(RAUTH_IMAGE)
		self.set_visible(True)
		self.set_tooltip('通过 Rauth 连接锐捷网络！')
		self.notify=Notify()
		self.notify.attach_to_status_icon(self)
		self.connect("popup_menu",self.on_popup)

		self.popmenu=gtk.Menu()
		self.connect_item=gtk.CheckMenuItem("连接")
		self.connect_item.show()

		self.quit_item=gtk.MenuItem("退出")
		self.quit_item.show()

		self.popmenu.append(self.connect_item)
		self.popmenu.append(self.quit_item)

	def set_state(self,conn):
		self.connect_item.set_active(conn)
		if not conn:
			warning="网络己断开"	
			self.set_tooltip('通过 Rauth 连接锐捷网络！\n'+
				'当前状态：己断开')
		else:
			warning="网络己连接"
			self.set_tooltip('通过 Rauth 连接锐捷网络！\n'+ 
				'当前状态：己连接')
		self.notify.update("Rauth 网络认证", warning, "dialog-warning")
		self.notify.show()

	def on_popup(self,widget,button,activate_time=None):
		self.popmenu.popup(parent_menu_shell=None,
				parent_menu_item=None,
				func=None,button=0,activate_time=activate_time)
icon = Icon()

if __name__ == "__main__":
        icon.notify(state=False)
	gtk.main()
